local skel = fk.CreateSkill {
  name = "emo__xuedie",
}

skel:addEffect("active", {
  anim_type = "drawcard",
  prompt = "#emo__xuedie-ask",
  times = function (self, player)
    return 1 - player:usedEffectTimes(self.name, Player.HistoryPhase)
  end,
  can_use = function(self, player)
    return player:usedEffectTimes(self.name, Player.HistoryPhase) < 1
    and (#player:getAvailableEquipSlots() > 0 or not table.contains(player.sealedSlots, Player.JudgeSlot) )
  end,
  card_num = 0,
  card_filter = Util.FalseFunc,
  target_num = 0,
  on_use = function(self, room, effect)
    local player = effect.from
    local choices = player:getAvailableEquipSlots()
    if not table.contains(player.sealedSlots, Player.JudgeSlot) then
      table.insert(choices, Player.JudgeSlot)
    end
    if #choices == 0 then return false end
    local choice = room:askToChoice(player, {choices = choices, skill_name = skel.name, prompt = "#emo__xuedie-ask"})
    room:abortPlayerArea(player, choice)
    if player.dead then return end
    if choice == Player.JudgeSlot then
      room:changeMaxHp(player, 1)
    else
      player:drawCards(2, skel.name)
    end
  end,
})

skel:addEffect(fk.TargetConfirming, {
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(skel.name) and (data.card.trueName == "slash" or data.card:isCommonTrick()) then
      return #player:getAvailableEquipSlots() > 0 or not table.contains(player.sealedSlots, Player.JudgeSlot)
    end
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {skill_name = skel.name, prompt = "#emo__xuedie-ask"})
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choices = player:getAvailableEquipSlots()
    if not table.contains(player.sealedSlots, Player.JudgeSlot) then
      table.insert(choices, Player.JudgeSlot)
    end
    if #choices == 0 then return false end
    local choice = room:askToChoice(player, {choices = choices, skill_name = skel.name, prompt = "#emo__xuedie-ask"})
    room:abortPlayerArea(player, choice)
    if player.dead then return end
    if choice == Player.JudgeSlot then
      room:changeMaxHp(player, 1)
      if data.card.sub_type == Card.SubtypeDelayedTrick then
        data:cancelTarget(player)
      end
    else
      player:drawCards(2, skel.name)
    end
  end,
})

Fk:loadTranslationTable{
  ["emo__xuedie"] = "血蝶",
  [":emo__xuedie"] = "出牌阶段限一次，或每当你成为【杀】或普通锦囊牌的目标时，你可以选一项：1.废除一个装备区，摸两张牌；2.废除判定区，增加一点体力上限。",
  ["#emo__xuedie-ask"] = "血蝶：你可以废除一个区域，装备区：摸两张牌，判定区：加体力上限",
}

return skel
